package com.iwop.moto.service.impl;

import com.iwop.moto.model.SuperRecordModel;
import com.iwop.moto.service.BaseService;
import com.iwop.moto.service.PromotionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Create by liuwb on 2016-08-24
 */
@Service("promotionService")
public class PromotionServiceImpl extends BaseService implements PromotionService{

    public static  String insertPromotion="MPromotionMapper.insertPromotion";
    public static  String findHostUserById="MPromotionMapper.findHostUserById";
    public static  String findPromotionByParams="MPromotionMapper.findPromotionByParams";
    public static  String deleteByFromUser="MPromotionMapper.deleteByFromUser";
    public static  String findUserByPromotionCount="MPromotionMapper.findUserByPromotionCount";
    public static  String findHostUserInfo="MPromotionMapper.findHostUserInfo";

    /**
     * @author Create by liuwb on 2016-08-24
     * @explain 新增角色关联数据
     * @param SRModel
     */
    public void insertPromotion(SuperRecordModel SRModel){
        getSqlSession().insert(insertPromotion,SRModel);
    }

    /**
     * @功能: 查询父级的服务商userid
     */
    public String findHostUserById(String userId){
        return getSqlSession().selectOne(findHostUserById,userId);
    }

    /**
     * @author Create by liuwb on 2016-08-30
     * @explain:  根据条件检索数据
     * @param SRModel
     */
    public List<SuperRecordModel> findPromotionByParams(SuperRecordModel SRModel){
        return getSqlSession().selectList(findPromotionByParams, SRModel);
    }

    /**
     * @author Create by liuwb on 2016-08-30
     * @explain: 根据推荐人id删除关联信息
     * @param SRModel
     */
    public void deleteByFromUser(SuperRecordModel SRModel){
        getSqlSession().delete(deleteByFromUser,SRModel);
    }

    /**
     * @功能: 获取服务商下面一级、二级分销成员数量
     * @param userId 服务商的userId
     */
    public Long findUserByPromotionCount(String userId){
       return (Long) getSqlSession().selectOne(findUserByPromotionCount,userId);
    }

    /**
     * @功能: 获取推荐人信息
     * @param user_id
     */
    public SuperRecordModel findHostUserInfo(String user_id){
        return  getSqlSession().selectOne(findHostUserInfo,user_id);
    }

    @Override
    public int countFromUserByHostId(String hostUserInfo) {
        return getSqlSession().selectOne("MPromotionMapper.countFromUserByHostId",hostUserInfo);
    }

    @Override
    public Long findUserCount(String userId) {
        return getSqlSession().selectOne("MPromotionMapper.findUserCount");
    }
}